.TH std::experimental::ranges::exchange 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::ranges::exchange \- std::experimental::ranges::exchange

.SH Synopsis
   Defined in header <experimental/ranges/utility>
   template< MoveConstructible T, class U = T >

       requires Assignable<T&, U>                                          (ranges TS)

   constexpr T exchange( T& obj, U&& new_val ) noexcept(/* see below */);

   Replaces the value of obj with new_value and returns the old value of obj, as if by

 T old_value = std::move(obj);
 obj = std::forward<U>(new_value);
 return old_value;

.SH Parameters

   obj       - object whose value to replace
   new_value - the value to assign to obj

.SH Return value

   The old value of obj.

.SH Exceptions

   noexcept specification:
   noexcept(std::is_nothrow_move_constructible<T>::value &&
            std::is_nothrow_assignable<T&, U>::value)

.SH Example

    This section is incomplete
    Reason: no example

.SH See also

   exchange replaces the argument with a new value and returns its previous value
   \fI(C++14)\fP  \fI(function template)\fP

.SH Categories:
     * conditionally noexcept
     * Todo no example
